import 'package:pinyin/pinyin.dart';

class FirstLetterUtil {
  static String _letters = 'abcdefghijklmnopqrstuvwxyz';

  static String firstLetter(String str) {
    if (str == null || str.length < 1) throw Exception("参数不能为空");
    String firstStr = str.substring(0, 1);
    String first = PinyinHelper.getShortPinyin(firstStr);
    String firstLetter = first.substring(0, 1);
    if (_letters.contains(firstLetter.toLowerCase())) {
      return firstLetter.toUpperCase();
    }
    return "#";
  }
}
